#include "util.hpp"

#define HOST "127.0.0.1"
#define USER "root"
#define PASSWD "sa1212@@"
#define DB "gobang"
#define PORT 3306


void loger_test(){
    // LOG("%s-%d\n","五子棋",666);
    // ILOG("1");
    // DLOG("2");
    // ELOG("3");
}


void mysql_test(){
    MYSQL*mysql=mysql_util::mysql_create(HOST,USER,PASSWD,DB,PORT);
    const char* sql="insert stu values(null,'小明',18,40,50,60)";
    int ret=mysql_util::mysql_exec(mysql,sql);
    if(ret==-1){
        return;
    }
    mysql_util::mysql_destroy(mysql);
}


void json_test(){
    Json::Value root;
    root["姓名"]="张三";
    root["年龄"]=18;
    root["成绩"].append(100);
    root["成绩"].append(89);
    root["成绩"].append(99.5);
    std::string str;
    json_util::serialize(root,str);
    std::cout<<str<<std::endl;

    Json::Value res;
    json_util::unserialize(str,res);
    std::cout<< "姓名: "<<res["姓名"].asString()<<std::endl;
    std::cout<< "年龄: "<<res["年龄"].asInt()<<std::endl;
    int sz=res["成绩"].size();
    for(int i=0;i<sz;++i){
        std::cout<<"成绩: "<<res["成绩"][i].asFloat()<<std::endl;
    }


}


void string_util_test(){
    std::vector<std::string> vs;
    std::string s=",,,123,,,456,,,,789,,";
    std::string seq=",";
    string_util::split(s,seq,vs);
    for(auto& e:vs){
        std::cout<<e<<std::endl;
    }
}


void file_util_test(){
    std::string filename="./logger.hpp";
    std::string body;
    bool ret=file_util::read(filename,body);
    if(ret==false){
        return;
    }
    std::cout<<body<<std::endl;
}

int main()
{
    file_util_test();
    return 0;
}